package fr.aquariophilie.org;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
 
public class connexion extends Dialog  implements OnClickListener{
 
	public Button  okButton;
	public Button   cancelButton;
	public ReadyListener readyListener;
 
 
	 public interface ReadyListener { 
         public void ready(String sUser,String sPass); 
    } 
 
	public connexion(Context context, ReadyListener readyListener) {
		super(context);
		this.readyListener = readyListener; 
	}
 
	/**
	* @see android.app.Dialog#onCreate(android.os.Bundle)
	*/
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		  Log.d("TestApp", "Dialog created");
			setContentView(R.layout.connexion);			
			okButton = (Button) findViewById(R.id.widget82);
			cancelButton = (Button) findViewById(R.id.widget83);			
			okButton.setOnClickListener(this);
			cancelButton.setOnClickListener(this);	
			findViewById(R.id.widget80);
			findViewById(R.id.widget81);
	}
 
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.widget83:
				dismiss();
			break;
			case R.id.widget82:
				try{			
					EditText textuser = (EditText) findViewById(R.id.widget80);
					EditText textpass = (EditText) findViewById(R.id.widget81);
					String sUser = textuser.getText()+"";
					String sPass = textpass.getText()+"";
 
					//appelle de la methode readyListener.ready et on passe en valeur le formatage
					readyListener.ready(sUser,sPass);
					//String u="kk";
				}catch(Exception e){
					TextView textbastmp2 = (TextView) findViewById(R.id.widget80);
					textbastmp2.setText(e.toString());
				}
			 break;
			}
		}  
	
}